package com.eduhzy.ttw.work.di.module;

import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.request.RequestOptions;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.eduhzy.ttw.commonsdk.holder.AutoBaseViewHolder;
import com.eduhzy.ttw.commonsdk.http.CommonApi;
import com.eduhzy.ttw.work.R;
import com.eduhzy.ttw.work.mvp.contract.WorkUnSubmitContract;
import com.eduhzy.ttw.work.mvp.model.WorkUnSubmitModel;
import com.eduhzy.ttw.work.mvp.model.entity.WorkClassData;
import com.jess.arms.di.scope.FragmentScope;

import java.util.ArrayList;
import java.util.List;

import dagger.Module;
import dagger.Provides;

/**
 * @author xubo
 * @date 2018-12-3 18:47:28
 */
@Module
public class WorkUnSubmitModule {
    private WorkUnSubmitContract.View view;

    /**
     * 构建WorkUnSubmitModule时,将View的实现类传进来,这样就可以提供View的实现类给presenter
     *
     * @param view
     */
    public WorkUnSubmitModule(WorkUnSubmitContract.View view) {
        this.view = view;
    }

    @FragmentScope
    @Provides
    WorkUnSubmitContract.View provideWorkUnSubmitView() {
        return this.view;
    }

    @FragmentScope
    @Provides
    WorkUnSubmitContract.Model provideWorkUnSubmitModel(WorkUnSubmitModel model) {
        return model;
    }



    @FragmentScope
    @Provides
    List<WorkClassData> provideLists() {
        return new ArrayList<>();
    }

    @FragmentScope
    @Provides
    BaseQuickAdapter<WorkClassData, AutoBaseViewHolder> providerAdapter(List<WorkClassData> lists) {
        return new BaseQuickAdapter<WorkClassData, AutoBaseViewHolder>(R.layout.work_rv_item_class_unread, lists) {
            @Override
            protected void convert(AutoBaseViewHolder helper, WorkClassData item) {
                Glide.with(mContext)
                        .load(CommonApi.APP_AVATAR+item.getUserId())
                        .apply(RequestOptions.placeholderOf(R.drawable.img_touxiang).centerCrop().diskCacheStrategy(DiskCacheStrategy.ALL))
                        .into((ImageView) helper.getView(R.id.iv_icon));
                helper.setText(R.id.tv_name, item.getUserRealName());
            }
        };
    }

    @FragmentScope
    @Provides
    RecyclerView.LayoutManager provideLayoutManager() {
        return new GridLayoutManager(view.getActivity(),4);
    }

}